package pojo;

import java.io.Serializable;
import java.util.Date;

import util.DateUtil;
import util.NumberUtil;

/*创建学生类
 * */
public class Student implements Serializable
{
	/*学生的学号*/
	private int id;
	private String name;
	private int age;
	/*学生的性别 true男 , false女*/
	private boolean sex;
	/*chinese 语文*/
	private double chinese;
	/*math 数学*/
	private double math;
	/*english 英语成绩*/
	private double english;
	/*总分*/
	private double totalSocre;
	private double avgSocre;
	/*入学时间*/
	private Date createTime;
	/*修改时间*/
	private Date updateTime;
	public int getId()
	{
		return id;
	}
	public void setId(int id)
	{
		this.id = id;
	}
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public int getAge()
	{
		return age;
	}
	public void setAge(int age)
	{
		this.age = age;
	}
	public boolean isSex()
	{
		return sex;
	}
	public void setSex(boolean sex)
	{
		this.sex = sex;
	}
	public double getChinese()
	{
		return chinese;
	}
	public void setChinese(double chinese)
	{
		this.chinese = chinese;
	}
	public double getMath()
	{
		return math;
	}
	public void setMath(double math)
	{
		this.math = math;
	}
	public double getEnglish()
	{
		return english;
	}
	public void setEnglish(double english)
	{
		this.english = english;
	}
	public double getTotalSocre()
	{
		/* 总分:语文+数学+英语 */
		this.totalSocre = this.chinese + english + this.math ; 
		return totalSocre;
	}
	public double getAvgSocre()
	{
		/*平均分,计算的时候有除不尽的需要保留小数*/
		this.avgSocre = this.totalSocre/3;
		/*格式化分数*/
		NumberUtil nu = new NumberUtil();
		/*类型之间的相互转换*/
		String re = nu.number(avgSocre);
		this.avgSocre = Double.valueOf(re);

		return avgSocre;
	}
	public Date getCreateTime()
	{
		return createTime;
	}
	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}
	public Date getUpdateTime()
	{
		return updateTime;
	}
	public void setUpdateTime(Date updateTime)
	{
		this.updateTime = updateTime;
	}
	/*重新生成自我介绍*/
	public String toString()
	{
		return "学号:"+ this.id +";姓名:"+ name +";年龄:"+ this.age +
				";性别:" + this.isSex() +";语文:" + this.chinese + 
				";数学:"+ this.math +";英文:"+ this.english +
				";总分:" + this.getTotalSocre() + ";平均分:" 
				+ this.getAvgSocre() + ";创建时间:" +
				this.getCreateTime() + ";更新时间:"+ this.getUpdateTime() +";" ; 
	}
	public String listStr()
	{
		/* 创建一个日期工具类 */
		DateUtil dateUtil = new DateUtil() ; 
		/* 格式化创建时间 */
		Date createTimeDate = this.getCreateTime() ;
		/* 将性别:男女化 */
		String sexStr = "" ; 
		if(this.sex)
		{
			sexStr = "男" ; 
		}else
		{
			sexStr = "女" ; 
		}
		/* 存储结果的字符串 */
		StringBuffer sb = new StringBuffer() ; 
		sb.append(this.getId() + "\t");
		sb.append(this.getName() + "\t");
		sb.append(this.getAge() + "\t");
		sb.append(sexStr + "\t");
		sb.append(this.getChinese() + "\t");
		sb.append(this.getMath() + "\t");
		sb.append(this.getEnglish() + "\t");
		sb.append(this.getTotalSocre() + "\t");
		sb.append(this.getAvgSocre() + "\t");
		sb.append(dateUtil.timeToString(this.getCreateTime())+ "\t");
		sb.append(dateUtil.timeToString(this.getUpdateTime()) + "\t");
		return sb.toString(); 
	}
}
